<template>
  <div class="cate_wrap">
    <div class="bread">
      <span>首页</span> &gt; <span>{{ name }}</span>
    </div>
    <banner-com :shownav="false"></banner-com>
    <div class="cate_all">
      <h1>全部分类</h1>
      <div class="all_list">
        <div class="all_one" v-for="(item, index) in cateList" :key="index">
          <img :src="item.picture" alt="" />
          <p>{{ item.name }}</p>
        </div>
      </div>
    </div>
    <div class="cate_now" v-for="(item, index) in cateList" :key="index">
      <div class="cate_title">
        <h1>- {{ item.name }} -</h1>
        <h3>真棒</h3>
      </div>
      <div class="now_list">
        <div class="now_one" v-for="(goodsItem, ind) in item.goods" :key="ind">
          <img :src="goodsItem.picture" alt="" />
          <div>{{ goodsItem.name }}</div>
          <div>{{ goodsItem.desc }}</div>
          <div style="color:red;">{{ goodsItem.price }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import bannerCom from '../Home/child/banner.vue'
import { _getCateOneInfo } from '../../api/category'
export default {
  components: { bannerCom },
  data () {
    return {
      id: '',
      cateList: [],
      name: ''
    }
  },
  created () {
    this.id = this.$route.params.id
    console.log(this.id)
    this.getCateInfo()
  },
  watch: {
    $route (newVal, oldVal) {
      console.log(newVal, oldVal)
      this.id = this.$route.params.id
      console.log(this.id)
      this.getCateInfo()
    }
  },
  methods: {
    async getCateInfo () {
      var res = await _getCateOneInfo(this.id)
      console.log(res)
      this.cateList = res.data.result.children
      this.name = res.data.result.name
    }
  }
}
</script>
<style lang="less" scoped>
.cate_wrap {
  width: 1240px;
  margin: 20px auto;
  .cate_all {
    width: 1240px;
    text-align: center;
    h1 {
      // color: #ccc;
      font-size: 25px;
    }
    .all_list {
      display: flex;
      .all_one {
        width: 168px;
        height: 160px;
        margin-right: 30px;
        img {
          width: 100px;
          height: 100px;
        }
      }
    }
  }
}
.cate_now {
  width: 1240px;
  margin-top: 20px;
  text-align: center;
  .now_list {
    display: flex;
    .now_one {
      width: 220px;
      height: 299px;
      margin-right: 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      &:hover {
        transition: all 0.5s;
        transform: scale(1.01);
        box-shadow: 2px 2px 2px #ccc, -2px -2px 2px #ccc;
      }
      img {
        width: 160px;
        height: 160px;
      }
    }
  }
}
</style>
